package com.companyName.sample.service.impl.sys;

import java.util.List;

import com.companyName.sample.bean.dto.sys.UserInfoDto;
import com.companyName.sample.common.bean.ResponseData;
import com.companyName.sample.common.constant.ResponseMsg;
import com.companyName.sample.common.exception.BusinessException;
import com.companyName.sample.data.entity.CityInfoPo;
import com.companyName.sample.data.entity.UserInfoExample;
import com.companyName.sample.data.entity.UserInfoPo;
import com.companyName.sample.service.impl.BaseService;
import com.companyName.sample.service.business.CityInfoBiz;
import com.companyName.sample.service.business.UserInfoBiz;
import com.companyName.sample.api.service.sys.IUserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
//@DependsOn()
public class UserInfoServiceImpl extends BaseService implements IUserInfoService {

    private static final Logger logger = LoggerFactory.getLogger(LogServiceImpl.class);
    @Autowired
    UserInfoBiz userInfoBiz;

    @Autowired
    CityInfoBiz cityInfoBiz;

    @Override
    public ResponseData<UserInfoDto> getUserInfo(Integer userId) throws BusinessException {
        UserInfoExample condition = new UserInfoExample();
        UserInfoDto res = userInfoBiz.getUserInfo(userId);
        return new ResponseData<UserInfoDto>(ResponseMsg.SUCCESS.getCode(), res);
    }

    @Override
    public ResponseData<List<UserInfoDto>> getUserInfoList(UserInfoDto req, int pageId, int pageSize) throws BusinessException {
        UserInfoExample condition = new UserInfoExample();
        BeanUtils.copyProperties(req, condition);
        List<UserInfoDto> res = userInfoBiz.getUserInfoList(condition, pageId, pageSize);
        return new ResponseData<List<UserInfoDto>>(ResponseMsg.SUCCESS.getCode(), res);
    }


    @Override
    public ResponseData<Integer> putUserInfo(UserInfoDto req) throws BusinessException {
        UserInfoPo userInfo = new UserInfoPo();
        BeanUtils.copyProperties(req, userInfo);
        int res1 = userInfoBiz.putUserInfo(userInfo);
        return new ResponseData<Integer>(ResponseMsg.SUCCESS.getCode(), new Integer(res1));
    }

    @Override
    public ResponseData<Integer> postUserInfo(UserInfoDto req) throws BusinessException {
        UserInfoPo condition = new UserInfoPo();
        BeanUtils.copyProperties(req, condition);
        int res = userInfoBiz.postUserInfo(condition);
        return new ResponseData<Integer>(ResponseMsg.SUCCESS.getCode(), new Integer(res));
    }


    @Override
    public ResponseData<Integer> deleteUserInfo(UserInfoDto req) throws BusinessException {
        UserInfoExample condition = new UserInfoExample();
        BeanUtils.copyProperties(req, condition);
        int res = userInfoBiz.deleteUserInfo(condition);
        return new ResponseData<Integer>(ResponseMsg.SUCCESS.getCode(), new Integer(res));
    }

    @Override
    public ResponseData<Integer> putUserInfoT(UserInfoDto req) throws BusinessException {
        UserInfoPo userInfo = new UserInfoPo();
        BeanUtils.copyProperties(req, userInfo);
        int res1 = userInfoBiz.putUserInfo(userInfo);

        CityInfoPo cityInfo = new CityInfoPo();
        if ("T".equals(req.getUsername())) {
            cityInfo = null;
        }
        int res2 = cityInfoBiz.putCityInfo(cityInfo);

        userInfoBiz.putUserInfoForCache(userInfo);
        cityInfoBiz.putCityInfoForCache(cityInfo);
        return new ResponseData<Integer>(ResponseMsg.SUCCESS.getCode(), new Integer(res1));
    }

    @Override
    public ResponseData<Integer> insertUserInfoT(UserInfoDto req) throws BusinessException {
        UserInfoPo userInfo = new UserInfoPo();
        BeanUtils.copyProperties(req, userInfo);
        int res1 = userInfoBiz.putUserInfo(userInfo);

        CityInfoPo cityInfo = new CityInfoPo();
        if ("T".equals(req.getUsername())) {
            cityInfo = null;
        }
        int res2 = cityInfoBiz.putCityInfo(cityInfo);

        userInfoBiz.putUserInfoForCache(userInfo);
        cityInfoBiz.putCityInfoForCache(cityInfo);
        return new ResponseData<Integer>(ResponseMsg.SUCCESS.getCode(), new Integer(res1));
    }



}
